package com.example.rdcproject.ving.notes.entity;

import com.example.rdcproject.ving.notes.entity.Announcement;


import java.util.List;


// 公告栏类
public class AnnouncementBoard {
    private List<Announcement> announcements;

    public void setAnnouncements(List<Announcement> announcements) {
        this.announcements = announcements;
    }

    // 获取所有公告列表
    public List<Announcement> getAnnouncements() {
        if (announcements == null) {
            return null;
        }
        return announcements;
    }

    // 根据 ID 获取公告
    public Announcement getAnnouncementById(int id) {
        for (int i = 0; i < announcements.size(); i++) {
           if( announcements.get(i).getId()==id){
                return announcements.get(i);
           }
        }
        return null;
        }

    //添加公告
    public void addAnnouncement(Announcement announcement) {
        announcements.add(announcement);
    }


    // 删除公告
    public void removeAnnouncement(int id) {
        for (Announcement announcement : announcements) {
            if(announcement.getId()==id){
                announcements.remove(announcement);
            }
        }
    }
    //修改公告
    public void modifyAnnouncement(int id, String newContent) {
        for (Announcement announcement : announcements) {
            if (announcement.getId() == id) {
                announcement.setContent(id, newContent);
            }
        }

    }

    }
